package com.practice.springboot.jpa.controller;

import com.practice.springboot.jpa.model.Book;
import com.practice.springboot.jpa.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author sai
 * @create 2020-08-23 4:54
 */
@RestController
public class BookController {

    @Autowired
    private BookService bookService ;

    @RequestMapping("/getBooksByAuthorStartingWith")
    public List<Book> getBooksByAuthorStartingWith(@RequestParam String author){
        return  bookService.getBooksByAuthorStartingWith(author) ;
    }

    @RequestMapping("/getMaxIdBook")
    public Book getMaxIdBook( ){
        return  bookService.getMaxIdBook( ) ;
    }

    @RequestMapping("/getBookByIdAndAuthor")
    public List<Book> getBookByIdAndAuthor(@RequestParam("author") String author,
                                           @RequestParam("id") Long id){
        return  bookService.getBookByIdAndAuthor(author,id) ;
    }

    @RequestMapping("/getBookByIdnAndName")
    public List<Book> getBookByIdnAndName(@RequestParam("id") Long id,
                                          @RequestParam("name")String name){
        return  bookService.getBookByIdnAndName(id,name) ;
    }

}
